package com.way;

import java.util.concurrent.locks.ReentrantLock;

/**
 * @author 魏彪
 */
public class Test {

//    static ReentrantLock lock = new ReentrantLock();
    static WayLock lock = new WayLock();

    public static void main(String[] args) {
        new Thread(new Runnable() {
            @Override
            public void run() {
                lock.lock();
                drawMoney();
                lock.unlock();
            }
        }, "线程1").start();

        new Thread(new Runnable() {
            @Override
            public void run() {
                lock.lock();
                drawMoney();
                lock.unlock();
            }
        }, "线程2").start();
    }

    private static void drawMoney() {
        System.out.println(Thread.currentThread().getName() + "正在取钱...");
        sleep(3000);
        System.out.println(Thread.currentThread().getName() + "取完了...");
    }

    private static void sleep(long mills) {
        try {
            Thread.sleep(mills);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
    }
}
